from datetime import datetime
from typing import Optional
import uuid
from pydantic import BaseModel, ConfigDict, field_validator
from app.schemas.base import BaseSchema


class ReportClassificationBase(BaseModel):
    name: str


class ReportClassificationCreate(ReportClassificationBase):
    @field_validator('name')
    @classmethod
    def validate_name(cls, v):
        if not v or not v.strip():
            raise ValueError('分类名称不能为空')
        if len(v.strip()) > 100:
            raise ValueError('分类名称长度不能超过100个字符')
        return v.strip()


class ReportClassificationUpdate(BaseModel):
    name: Optional[str] = None

    @field_validator('name')
    @classmethod
    def validate_name(cls, v):
        if v is not None:
            if not v or not v.strip():
                raise ValueError('分类名称不能为空')
            if len(v.strip()) > 100:
                raise ValueError('分类名称长度不能超过100个字符')
            return v.strip()
        return v


class ReportClassification(BaseSchema):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    name: str
    created_at: datetime
    updated_at: datetime